<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div>0</div>
    <button onclick="fn()">点击</button>
    <script>
        let div = document.querySelector("div");



        function fn() {
            let i = 0;
            let BDiv = div.innerHTML;
            if (i < 10) {
                setInterval(() => {
                    div.innerHTML = i++;
                }, 500)
            } else {
                clearInterval();
            };
        }

        //
        console.time("test");
        
        setTimeout("for(var i=0;i<1000000;i++)console.log('定时器!');",1000);

        console.log("测试");
        console.timeEnd("test");
    </script>
</body>

</html>